package org.springblade.modules.app.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.tool.api.R;
import org.springblade.modules.app.dto.LndxCourseDTO;
import org.springblade.modules.app.entity.LndxCourseCategory;
import org.springblade.modules.app.service.LndxCourseCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("blade-app/helpstar")
public class LndxCourseCategoryByHelpStarController extends BladeController {

    @Autowired
    private LndxCourseCategoryService lndxCourseCategoryService;


    @GetMapping("/courseTypePageBySearch")
    public R<IPage<LndxCourseCategory>> courseTypePageBySearch(Page page, LndxCourseCategory lndxCourseCategory) {
        LambdaQueryWrapper<LndxCourseCategory> queryWrapper = new LambdaQueryWrapper<>();
        if (!StringUtils.isEmpty(lndxCourseCategory.getCatename())) {
            queryWrapper.and(wrapper -> wrapper.like(LndxCourseCategory::getCatename, lndxCourseCategory.getCatename()));
        }
        IPage<LndxCourseCategory> pages = lndxCourseCategoryService.page(page,queryWrapper);
        return R.data(pages);
    }


    ///get seris
    @GetMapping("/getSeriesList")
    public List<LndxCourseCategory> getSeriesList(LndxCourseCategory lndxCourseCategory) {
        LambdaQueryWrapper<LndxCourseCategory> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.and(wrapper -> wrapper.eq(LndxCourseCategory::getParentid, "0"));
        List<LndxCourseCategory> list = lndxCourseCategoryService.list(queryWrapper);
        return list;
    }

    ///get apptype
    @GetMapping("/getApptypeBySeriesId")
    public List<LndxCourseCategory> getApptypeBySeriesId(LndxCourseCategory lndxCourseCategory) {
        LambdaQueryWrapper<LndxCourseCategory> queryWrapper = new LambdaQueryWrapper<>();
        if (!StringUtils.isEmpty(lndxCourseCategory.getId())) {
            queryWrapper.and(wrapper -> wrapper.eq(LndxCourseCategory::getParentid, lndxCourseCategory.getId()));
        }
        List<LndxCourseCategory> list = lndxCourseCategoryService.list(queryWrapper);
        return list;
    }


    ///get getClassByAppId
    @GetMapping("/getClassByAppId")
    public List<LndxCourseCategory> getClassByAppId(LndxCourseCategory lndxCourseCategory) {
        LambdaQueryWrapper<LndxCourseCategory> queryWrapper = new LambdaQueryWrapper<>();
        if (!StringUtils.isEmpty(lndxCourseCategory.getId())) {
            queryWrapper.and(wrapper -> wrapper.eq(LndxCourseCategory::getParentid, lndxCourseCategory.getId()));
        }
        List<LndxCourseCategory> list = lndxCourseCategoryService.list(queryWrapper);
        return list;
    }
}
